/**
 * Copyright (c) 2015 www.smarthome.com All rights reserved. <br />
 * 本软件源代码版权归xxxx公司,未经许可不得任意复制与传播.<br />
 *
 */
package com.smarthome.core.deviceManager.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShEquipmentProducerService;
import com.smarthome.core.deviceManager.EquipmentProducerService;
import com.smarthome.domain.bean.ShEquipmentProducer;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * 设备供应商service层
 * @author szc
 *
 */
@Service("deviceSupplierService")
public class EquipmentProducerServiceImpl implements EquipmentProducerService {

    protected static Logger LOGGER;

    @Resource
    private ShEquipmentProducerService shEquipmentProducerService;

    /**
     * 查询供应商信息列表
     * @param deviceSupplier
     * @param page
     * @return
     */
    @Override
    public DataGrid dataGrid(ShEquipmentProducer equipmentProducer, PageHelper page) {
        return shEquipmentProducerService.queryShDeviceSupplierPage(equipmentProducer, page);
    }

    /**
     * 新增数据
     */
    @Override
    public void add(ShEquipmentProducer equipmentProducer) {
        shEquipmentProducerService.saveOrUpdate(equipmentProducer);
    }

    /**
     * 通过id主键，得到对象信息
     */
    @Override
    public ShEquipmentProducer queryShDeviceSupplierById(Long id) {
        return shEquipmentProducerService.selectEntryById(id);
    }

    /**
     * 修改
     */
    @Override
    public void edit(ShEquipmentProducer equipmentProducer) {
        shEquipmentProducerService.saveOrUpdate(equipmentProducer);
    }

    /**
     * 更新
     * @param equipmentProducer
     * @author KongXiangyu
     */
    public void saveOrUpdate(ShEquipmentProducer equipmentProducer) {
        shEquipmentProducerService.saveOrUpdate(equipmentProducer);
    }

    /***
     * 得到设备供应商下拉选项
     */
    @Override
    public List<Combobox> getShEquipmentProducerCombobox(boolean flag) {
        List<Combobox> result = new ArrayList<>();
        if (flag) {
            Combobox combobox = new Combobox();
            combobox.setValue("");
            combobox.setText("--请选择--");
            combobox.setSelected(true);
            result.add(combobox);
        }
        ShEquipmentProducer equipmentProducer = new ShEquipmentProducer();
        equipmentProducer.setOrderField("id");
        equipmentProducer.setOrderFieldType("ASC");
        List<ShEquipmentProducer> shDeviceSupplierList = this.queryShEquipmentProducerList(equipmentProducer);
        // 转combobox
        for (ShEquipmentProducer type : shDeviceSupplierList) {
            Combobox combobox = new Combobox();
            combobox.setValue(type.getId().toString());
            combobox.setText(type.getName());// 供应商名称
            result.add(combobox);
        }
        return result;
    }

    @Override
    public List<ShEquipmentProducer> queryShEquipmentProducerList(ShEquipmentProducer equipmentProducer) {
        return shEquipmentProducerService.selectEntryList(equipmentProducer);
    }

}
